package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class UploadFileController {

    @RequestMapping("/upload")
    public String FileUpload(String username, MultipartFile picImg) throws IOException {
        System.out.println("名字为"+username);

        String originalFilename = picImg.getOriginalFilename(); /*获取文件名字*/
        picImg.transferTo(new File("D:\\软件\\apache-tomcat-8.5.78\\upload\\"+originalFilename));
        return "success";
    }

    @RequestMapping("/moreUpload")
    public String MoreFileUpload(String username, MultipartFile[] picImg) throws IOException {
        for (MultipartFile item : picImg){
            String originalFilename = item.getOriginalFilename();
            item.transferTo(new File("D:\\软件\\apache-tomcat-8.5.78\\upload\\"+originalFilename));
        }

        return "success";
    }
}
